home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / travrusa.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  7KB  |  274 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Traverse USA
  6.  
  7. L Taylor
  8. J Clegg
  9.  
  10.   Functions to emulate the video hardware of the machine.
  11.  
  12. ***************************************************************************/
  13.  
  14. #include "driver.h"
  15.  
  16. extern unsigned char *spriteram;
  17. extern size_t spriteram_size;
  18.  
  19. unsigned char *travrusa_videoram;
  20.  
  21. static struct tilemap *bg_tilemap;
  22. static int flipscreen;
  23.  
  24.  
  25.  
  26. /***************************************************************************
  27.  
  28.   Convert the color PROMs into a more useable format.
  29.  
  30.   Traverse USA has one 256x8 character palette PROM (some versions have two
  31.   256x4), one 32x8 sprite palette PROM, and one 256x4 sprite color lookup
  32.   table PROM.
  33.  
  34.   I don't know for sure how the palette PROMs are connected to the RGB
  35.   output, but it's probably something like this; note that RED and BLUE
  36.   are swapped wrt the usual configuration.
  37.  
  38.   bit 7 -- 220 ohm resistor  -- RED
  39.         -- 470 ohm resistor  -- RED
  40.         -- 220 ohm resistor  -- GREEN
  41.         -- 470 ohm resistor  -- GREEN
  42.         -- 1  kohm resistor  -- GREEN
  43.         -- 220 ohm resistor  -- BLUE
  44.         -- 470 ohm resistor  -- BLUE
  45.   bit 0 -- 1  kohm resistor  -- BLUE
  46.  
  47. ***************************************************************************/
  48. void travrusa_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  49. {
  50.     int i;
  51.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  52.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  53.  
  54.  
  55.     /* character palette */
  56.     for (i = 0;i < 128;i++)
  57.     {
  58.         int bit0,bit1,bit2;
  59.  
  60.  
  61.         /* red component */
  62.         bit0 = 0;
  63.         bit1 = (*color_prom >> 6) & 0x01;
  64.         bit2 = (*color_prom >> 7) & 0x01;
  65.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  66.         /* green component */
  67.         bit0 = (*color_prom >> 3) & 0x01;
  68.         bit1 = (*color_prom >> 4) & 0x01;
  69.         bit2 = (*color_prom >> 5) & 0x01;
  70.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  71.         /* blue component */
  72.         bit0 = (*color_prom >> 0) & 0x01;
  73.         bit1 = (*color_prom >> 1) & 0x01;
  74.         bit2 = (*color_prom >> 2) & 0x01;
  75.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  76.  
  77.         color_prom++;
  78.     }
  79.  
  80.     /* skip bottom half - not used */
  81.     color_prom += 128;
  82.  
  83.     /* sprite palette */
  84.     for (i = 0;i < 32;i++)
  85.     {
  86.         int bit0,bit1,bit2;
  87.  
  88.  
  89.         /* red component */
  90.         bit0 = 0;
  91.         bit1 = (*color_prom >> 6) & 0x01;
  92.         bit2 = (*color_prom >> 7) & 0x01;
  93.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  94.         /* green component */
  95.         bit0 = (*color_prom >> 3) & 0x01;
  96.         bit1 = (*color_prom >> 4) & 0x01;
  97.         bit2 = (*color_prom >> 5) & 0x01;
  98.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  99.         /* blue component */
  100.         bit0 = (*color_prom >> 0) & 0x01;
  101.         bit1 = (*color_prom >> 1) & 0x01;
  102.         bit2 = (*color_prom >> 2) & 0x01;
  103.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  104.  
  105.         color_prom++;
  106.     }
  107.  
  108.     /* color_prom now points to the beginning of the lookup table */
  109.  
  110.     /* character lookup table */
  111.     for (i = 0;i < TOTAL_COLORS(0);i++)
  112.         COLOR(0,i) = i;
  113.  
  114.     /* sprite lookup table */
  115.     for (i = 0;i < TOTAL_COLORS(1);i++)
  116.         COLOR(1,i) = *(color_prom++) + 128;
  117. }
  118.  
  119.  
  120.  
  121. /***************************************************************************
  122.  
  123.   Callbacks for the TileMap code
  124.  
  125. ***************************************************************************/
  126.  
  127. static void get_tile_info(int tile_index)
  128. {
  129.     unsigned char attr = travrusa_videoram[2*tile_index+1];
  130.     SET_TILE_INFO(0,travrusa_videoram[2*tile_index] + ((attr & 0xc0) << 2),attr & 0x0f)
  131.     tile_info.flags = 0;
  132.     if (attr & 0x20) tile_info.flags |= TILE_FLIPX;
  133.     if (attr & 0x10) tile_info.flags |= TILE_FLIPY;
  134.     if ((attr & 0x0f) == 0x0f) tile_info.flags |= TILE_SPLIT(1);    /* hack */
  135. }
  136.  
  137.  
  138.  
  139. /***************************************************************************
  140.  
  141.   Start the video hardware emulation.
  142.  
  143. ***************************************************************************/
  144.  
  145. int travrusa_vh_start(void)
  146. {
  147.     bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,TILEMAP_SPLIT,8,8,64,32);
  148.  
  149.     if (!bg_tilemap)
  150.         return 1;
  151.  
  152.     bg_tilemap->transmask[0] = 0xff; /* split type 0 is totally transparent in front half */
  153.     bg_tilemap->transmask[1] = 0x3f; /* split type 1 has pens 6 and 7 opaque - hack! */
  154.  
  155.     tilemap_set_scroll_rows(bg_tilemap,32);
  156.  
  157.     return 0;
  158. }
  159.  
  160.  
  161.  
  162. /***************************************************************************
  163.  
  164.   Memory handlers
  165.  
  166. ***************************************************************************/
  167.  
  168. WRITE_HANDLER( travrusa_videoram_w )
  169. {
  170.     if (travrusa_videoram[offset] != data)
  171.     {
  172.         travrusa_videoram[offset] = data;
  173.         tilemap_mark_tile_dirty(bg_tilemap,offset/2);
  174.     }
  175. }
  176.  
  177.  
  178. static int scrollx[2];
  179.  
  180. static void set_scroll(void)
  181. {
  182.     int i;
  183.  
  184.     for (i = 0;i < 24;i++)
  185.         tilemap_set_scrollx(bg_tilemap,i,scrollx[0] + 256 * scrollx[1]);
  186.     for (i = 24;i < 32;i++)
  187.         tilemap_set_scrollx(bg_tilemap,i,0);
  188. }
  189.  
  190. WRITE_HANDLER( travrusa_scroll_x_low_w )
  191. {
  192.     scrollx[0] = data;
  193.     set_scroll();
  194. }
  195.  
  196. WRITE_HANDLER( travrusa_scroll_x_high_w )
  197. {
  198.     scrollx[1] = data;
  199.     set_scroll();
  200. }
  201.  
  202.  
  203. WRITE_HANDLER( travrusa_flipscreen_w )
  204. {
  205.     /* screen flip is handled both by software and hardware */
  206.     data ^= ~readinputport(4) & 1;
  207.  
  208.     flipscreen = data & 1;
  209.     tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  210.  
  211.     coin_counter_w(0,data & 0x02);
  212.     coin_counter_w(1,data & 0x20);
  213. }
  214.  
  215.  
  216.  
  217. /***************************************************************************
  218.  
  219.   Display refresh
  220.  
  221. ***************************************************************************/
  222.  
  223. static void draw_sprites(struct osd_bitmap *bitmap)
  224. {
  225.     int offs;
  226.     static struct rectangle spritevisiblearea =
  227.     {
  228.         1*8, 31*8-1,
  229.         0*8, 24*8-1
  230.     };
  231.     static struct rectangle spritevisibleareaflip =
  232.     {
  233.         1*8, 31*8-1,
  234.         8*8, 32*8-1
  235.     };
  236.  
  237.  
  238.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  239.     {
  240.         int sx,sy,flipx,flipy;
  241.  
  242.  
  243.         sx = ((spriteram[offs + 3] + 8) & 0xff) - 8;
  244.         sy = 240 - spriteram[offs];
  245.         flipx = spriteram[offs + 1] & 0x40;
  246.         flipy = spriteram[offs + 1] & 0x80;
  247.         if (flipscreen)
  248.         {
  249.             sx = 240 - sx;
  250.             sy = 240 - sy;
  251.             flipx = !flipx;
  252.             flipy = !flipy;
  253.         }
  254.  
  255.         drawgfx(bitmap,Machine->gfx[1],
  256.                 spriteram[offs + 2],
  257.                 spriteram[offs + 1] & 0x0f,
  258.                 flipx,flipy,
  259.                 sx,sy,
  260.                 flipscreen ? &spritevisibleareaflip : &spritevisiblearea,TRANSPARENCY_PEN,0);
  261.     }
  262. }
  263.  
  264. void travrusa_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  265. {
  266.     tilemap_update(ALL_TILEMAPS);
  267.  
  268.     tilemap_render(ALL_TILEMAPS);
  269.  
  270.     tilemap_draw(bitmap,bg_tilemap,TILEMAP_BACK);
  271.     draw_sprites(bitmap);
  272.     tilemap_draw(bitmap,bg_tilemap,TILEMAP_FRONT);
  273. }
  274.